package leecode

func corpFlightBookings(bookings [][]int, n int) []int {
	lastMax := n                   //求出最远航班
	diff := make([]int, lastMax+2) //差分数组 表示飞机上预定的座位
	for _, booking := range bookings {
		diff[booking[0]] += booking[2] //上飞机 , 飞机上的座位
		//判断是否超出最后一战
		diff[booking[1]+1] -= booking[2] //下飞机 , 飞机上剩余的座位
	}
	prefix := make([]int, 0)
	count := 0
	for i := 0; i < len(diff); i++ {
		count += diff[i]
		prefix = append(prefix, count)
	}
	return prefix[1 : len(prefix)-1]
}
